<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    
	
	<title>_边收边上架详细信息</title>
	
    <script type="text/javascript">
    	//init打印机
	  /* function initPrinter() {
		  packFormPrinter("printerBody");
	  }
	//打印
	  function clickPrinter() {  
		var ids="";
		  $("#rdcontentTable")
			.find("tr")
			.each(
					function(i) {
						if(i>0){
							if($(this).attr("id")!=undefined){
								ids+=$(this).attr("id")+",";
							}
							
						}
					});
		  if(ids.length==0){
			  alert("需要打印的收货明细为空!");
			  return false;
		  }
		  $.ajax({
			   type : 'post',
				url : '${ctx}/v2_instorageBillNew/printInstorageBillDetail',
				async:false,
				data : {
					ids:ids
				},
				dataType : 'json',
				success : function(data) {
					var status=data.status;
					var content = data.content;
					var rowNum = 1 ;
					if( status=='success'){
						//打印
						  var printName = $("#printerBody").val();
					       var billCode="${inBill.billCode}";
						  LODOP.PRINT_INIT(billCode);
						  LODOP.ADD_PRINT_BARCODE("0mm", "40mm", "45mm", "10mm", "128Auto", billCode);
						 // LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A5") ;
						  LODOP.ADD_PRINT_TABLE(50,0, "100%","100%",document.getElementById("div3").innerHTML);
						  if (LODOP.SET_PRINTER_INDEXA(printName)) {
								LODOP.PRINT(); 
						  }
					}else{
						alert(content);
					}
				},
				error : function() {
					jAlert("网络繁忙，请稍后重试...","温馨提示");
				}
			}); 
	  } */
	  function printNow(){
		  var billCodeArr=$("#code").val().split("_");
		  var printName=$("#instorageBillNewPrinter").val();
		  var page=$("#printPageNum").val();
		  $.ajax({
				type : 'post',
				url  : '${ctx}/v2_instorageBillNew/printInstorageBillDetail',
				data : {
					printType:billCodeArr[0],
					billCode:billCodeArr[1]
				},
				async: false,
				dataType : 'json',
				success : function(data) {
					if(data.status="success"){
						if(billCodeArr[0]=="1"){
							printYSPage(data);
						}else{
							printSJPage(data);
						}
						
					}
				},
				error : function() {
					alert("查询数据错误！");
				}
			}); 
	  }
	  function printYSPage(data){
		  var instorageBill=data.instorageBill;
		  var receiptDate=data.receiptDate==""? "":data.receiptDate[0].createTime;
			var str ="";
			var printNum=instorageBill.printYsnum>1 ? "C"+instorageBill.printYsnum:"";
			str += "<table cellpadding='0' cellspacing='0' align = 'center' border='1'>";
			str += "<thead>";
			str += "<tr><td colspan='7' align = 'center'><h3>验收单</h3></td></tr>";
			str += "<tr><td colspan='7'><font color='red'><b>"+printNum+"</b></font></td></tr>";
			str += "<tr>";
			str += "<th  colspan= '3'>客户单号:"+instorageBill.preBill.customerOrderNo+"</th ><th  colspan= '4'>单据日期:"+date2str(new Date(instorageBill.createTime.time),"yyyy-MM-d h:m:s")+"</th >";
			str += "</tr>";
			str += "</thead>";
			str += "<tbody>";
			str += "<tr>";
			str += "<td colspan= '2'>仓库:"+instorageBill.inwarehouse.groupName+"</td><td>商家:"+instorageBill.customer.customerName+"</td><td colspan= '4' align = 'left'>入库单号:"+instorageBill.billCode+"</td>";
			str += "</tr>";
			str += "<tr style='font-size:12pt'><td width='6%'>序号</td><td width='18%'>sku</td><td width='31%'>sku名称</td><td width='10%'>生产日期</td><td width='15%'>规格</td><td width='10%' >预约数量</td><td width='10%'>实收数量</td></tr>";
			$.each(data.instorageBillItemYSList,function(i){
				str +="<tr style='font-size:12pt' ><td>"+(i+1)+"</td><td>"+data.instorageBillItemYSList[i].skuCode+"</td><td>"+data.instorageBillItemYSList[i].skuName+"</td><td></td><td>"+data.instorageBillItemYSList[i].spec+"</td><td align = 'right'>"+data.instorageBillItemYSList[i].goodsNum+"</td>"+
					"<td align = 'right'>"+data.instorageBillItemYSList[i].countNum+"</td></tr>";
			})
			str += "</tbody>";
			str += "<tfoot align = 'center'>";
			str += "<tr><td colspan= '5'></td><td align = 'right' tdata='Sum' format='#'>######</td><td align = 'right' tdata='Sum' format='#'>######</td></tr>";
			str += "<tr><td colspan= '2' align = 'left'>收货人:</td><td colspan= '2' align = 'left'>打印日期:"+date2str(new Date(),"yyyy-MM-d h:m:s")+"</td><td colspan= '3' align = 'left'>收货日期:"+receiptDate+"</td></tr>";
			str += "<tr><td colspan= '2' align = 'left'>客户签字:</td><td colspan= '5' align = 'left'>签字日期:</td></tr>";
			str += "</tfoot>";
			str += "</table>";
			printTableAndBARCODE(instorageBill.billCode,$("#instorageBillNewPrinter").val(),"A4",$("#printPageNum").val(),0,154,45,10,str);
	 }
	  function printSJPage(data){
		  var instorageBill=data.instorageBill;
		  var receiptDate=data.receiptDate==""? "":data.receiptDate[0].createTime;
			var str ="";
			var printNum=instorageBill.printSjnum>1 ? "C"+instorageBill.printSjnum:"";
			str += "<table cellpadding='0' cellspacing='0' align = 'center' border='1'>";
			str += "<thead>";
			str += "<tr><td colspan='7' align = 'center'><h3>上架单</h3></td></tr>";
			str += "<tr><td colspan='7'><font color='red'><b>"+printNum+"</b></font></td></tr>";
			str += "<tr>";
			str += "<th  colspan= '4'>客户单号:"+instorageBill.preBill.customerOrderNo+"</th ><th  colspan= '3'>商家:"+instorageBill.customer.customerName+"</th >";
			str += "</tr>";
			str += "</thead>";
			str += "<tbody>";
			str += "<tr>";
			str += "<td colspan= '4' align = 'left'>入库单号:"+instorageBill.billCode+"</td><td colspan= '3' ></td>";
			str += "</tr>";
			str += "<tr style='font-size:12pt'><td width='6%'>序号</td><td width='15%'>报损状态</td><td width='10%'>LPN</td><td width='18%'>sku</td><td width='31%'>sku名称</td><td width='10%' >待上架数量</td><td width='10%'>库位编码</td></tr>";
			$.each(data.instorageBillItemSJList,function(i){
				str +="<tr style='font-size:12pt' ><td>"+(i+1)+"</td><td>"+data.instorageBillItemSJList[i].errorFlag+"</td><td>"+data.instorageBillItemSJList[i].lpn+"</td><td>"+data.instorageBillItemSJList[i].sku+"</td><td>"+data.instorageBillItemSJList[i].skuName+"</td><td align = 'right'>"+data.instorageBillItemSJList[i].unUpNum+"</td>"+
					"<td></td></tr>";
			})
			str += "</tbody>";
			str += "<tfoot align = 'center'>";
			str += "<tr><td colspan= '5'></td><td align = 'right' tdata='Sum' format='#'>######</td><td></td></tr>";
			str += "<tr><td colspan= '2' align = 'left'>收货人:</td><td colspan= '2' align = 'left'>打印日期:"+date2str(new Date(),"yyyy-MM-d h:m:s")+"</td><td colspan= '3' align = 'left'>收货日期:"+receiptDate+"</td></tr>";
			str += "</tfoot>";
			str += "</table>";
			printTableAndBARCODE(instorageBill.billCode,$("#instorageBillNewPrinter").val(),"A4",$("#printPageNum").val(),0,154,45,10,str);
	}
	  function exportExcel(){
		  var xx="<table>"
		  $("tr").each(function(){
			  xx+="<tr>"
	          xx+=$(this).html();
			  xx+="</tr>"
	      })
	      xx+="</table>";

		  LODOP=getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));  
		  LODOP.PRINT_INIT("");
		  LODOP.ADD_PRINT_TABLE(50,0, "100%","100%",xx);
		  LODOP.SET_SAVE_MODE("QUICK_SAVE",true);//快速生成（无表格样式,数据量较大时或许用到）
		  LODOP.SAVE_TO_FILE("新文件名.xls");
		
	  }
	//获得打印机的个数
	  function getPrinterCount() {
			LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
			return LODOP.GET_PRINTER_COUNT();
	  }
	//根据打印机序号获得打印机名称
	  function getPrinterName(iPrinterNO) {
			LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
			return LODOP.GET_PRINTER_NAME(iPrinterNO);
	  }
	</script>
	
</head>



<body>
<section class="content" id="content">
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
				<i class="fa fa-list"></i>
					<h3 class="box-title">边收边上架入库单信息</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body" id="div1">
				
	<!-- 入库单信息 -->
	
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<tr>
		    <th>商家</th>
		    <th>入库单号</th>
		    <th>相关单号</th>
		    <th>客户单号</th>
		    <th>入库仓</th>
		    <th>入库时间</th>
		</tr>
		<tr>
		   <td>${inBill.customer.customerName}</td>
		   <td>${inBill.billCode}</td>
		   <td>${inBill.aboutCode}</td>
		   <td>${inBill.preBill.customerOrderNo}</td>
		   <td>${inBill.inwarehouse.groupName}</td>
		   <td>${fn:substring(inBill.createTime,0,19)}</td>
		</tr>
	</table>
	</div>
	</div>
	</div>
	</div>
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
				<i class="fa fa-list"></i>
					<h3 class="box-title">预约数据</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body" id="div2">
	<!-- 入库数据 -->
	<table id="precontentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
		    <th>序号</th>
		    <th>SKU</th>
			<th>商品名称</th>
			<th>预约数量</th>
		    <th>收货数量</th>
			<th>上架数量</th>
		 </tr></thead>
		 
		 <c:forEach  items="${preInstorageDetail}" var="item" varStatus="i">
			 <tr>
			   <td>${i.count}</td>
			   <td>${item.sku}</td>
			   <td>${item.skuName}</td>
			   <td>${item.goodsNum}</td>
			   <td>${item.countNum}</td>
			   <td>${item.upNum}</td>
			 </tr>
		 </c:forEach>
	</table>
	</div>
	</div>
	</div>
	</div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
				<i class="fa fa-list"></i>
					<h3 class="box-title">收货明细</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
	<div class="box-body" id="div3" >
	<!-- 入库数据 -->
	<a class="btn btn-primary" onclick="initPrint(this,'selextPrinter','instorageBillNewPrinter','code','1_${inBill.billCode}');" >打印验收单</a>
	<a class="btn btn-primary" onclick="initPrint(this,'selextPrinter','instorageBillNewPrinter','code','2_${inBill.billCode}');" >打印上架单</a>
	<a   class="btn btn-primary" onclick="exportExcel();" >导出到Excel</a>
	<table id="rdcontentTable" class="table table-striped table-bordered table-condensed" border='1'>
		<thead><tr>
		    <th>序号</th>
			<th>报损状态</th>
			<th>LPN</th>
			<th>SKU</th>
			<th>商品名称</th>
		    <th>收货数量</th>
			<th>上架数量</th>
			<th>库位编码</th>
			<!-- <th>打印标志</th> -->
		 </tr></thead>
		 
		 <c:forEach  items="${receiptDetailList}" var="item" varStatus="i">
			 <tr id=${item.id}>
			   <td>${i.count}</td>
			   <td>
			   	 <c:if test="${item.errorFlag eq 'error'}"><font color=red>破损件</font></c:if>
			     <c:if test="${item.errorFlag ne 'error'}"><font color=black>正常件</font></c:if> 
			   </td>
			   <td>${item.lpnNo}</td>
			   <td>${item.sku}</td>
			   <td>${item.skuName}</td>
			   <td>${item.countNum}</td>
			   <td>${item.upNum}</td>
			   <td>${item.stockCode}</td>
			 <!--  <td>
				  <c:if test="${item.printFlag eq '1'}"><font color=red>C</font></c:if>
			      <c:if test="${item.errorFlag ne '1'}"><font color=black></font></c:if> 
			   </td>
			    -->
			 </tr>
		 </c:forEach>
		 
		 
	</table>
	</div>
	</div>
	</div>
	</div>
	</div>
	
	<!-- 打印条码窗体1 -->
	<div  class="modal  fade" id="selextPrinter" >
		 <div class="modal-dialog" >		 
		<div class="modal-content">
		 <div class="modal-header">
			    <button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">
					×
				</button>
			  <h3 id="myModalLabel">
                                                       打印信息
			</h3>
			<span id="messageLable"></span>
			<input type="hidden" id="code"/>
		  </div>
			
		  <div class="modal-body" style="margin-left: 100px;">
			 <div class="control-group">
					<div class="controls">
						  选择打印机:
						<select id="instorageBillNewPrinter" name="instorageBillNewPrinter" >

						</select>
					</div>
					<div class="controls">
						  打印张数:
						<input type="text" id="printPageNum" name="printPageNum" value="1"/>
					</div>
			 </div>
		  </div>
			
		  <div class="modal-footer">
		      <a role="button" id="printer" class="btn btn-primary" onclick="printNow();"  data-dismiss="modal">开始打印</a>
			  <button class="btn btn-primary"  data-dismiss="modal" aria-hidden="true">取消</button>
		  </div>
		  </div>
		
		 </div>
	</div>
</section>	
</body>
</html>
